<template>
    <div class="app-container">
        <el-row :gutter="10" class="panel-group">
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel" >
                <div class="card-panel-description">
                  <div class="card-panel-text" style="color: #333333;">
                      订单应付：￥<count-to :start-val="0" :end-val="platAmount.payable" :duration="1000" decimals="2" class="card-panel-num" />
                  </div>
                  <div class="card-panel-text" style="font-size:14px;">
                      实付：￥<count-to :start-val="0" :end-val="platAmount.pay" :duration="1000" class="card-panel-num" decimals="2" style="font-size:14px;" />
                      <span style="margin-left:15px;"></span>
                      优惠：￥<count-to :start-val="0" :end-val="platAmount.couponAmount" :duration="1000" class="card-panel-num" decimals="2" style="font-size:14px;" />
                  </div>
                </div>
            </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel">
                <div class="card-panel-description">
                  <div class="card-panel-text" style="color: #333333;">
                      平台收入：
                      ￥<count-to :start-val="0" :end-val="platAmount.platFee" :duration="1000" class="card-panel-num" decimals="2" />
                  </div>
                  <div class="card-panel-text" style="font-size:14px;">
                      服务收入：
                      ￥<count-to :start-val="0" :end-val="platAmount.serviceFee" :duration="1000" class="card-panel-num" decimals="2" style="font-size:14px;" />
                      <span style="margin-left:10px;"></span>
                      推广：
                      ￥<count-to :start-val="0" :end-val="platAmount.inviteFee" :duration="1000" class="card-panel-num" decimals="2" style="font-size:14px;" />
                  </div>
                  <div class="card-panel-text" style="font-size:14px;">
                      平台奖励：
                      ￥<count-to :start-val="0" :end-val="platAmount.invitePlatformFee" :duration="1000" class="card-panel-num" decimals="2" style="font-size:14px;" />
                  </div>
                </div>
            </div>
            </el-col>
            
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel">
                <div class="card-panel-description">
                  <div class="card-panel-text" style="color: #333333;">
                    扣款罚款：
                    ￥<count-to :start-val="0" :end-val="platAmount.receiveFineFee + platAmount.userFineFee" :duration="1000" class="card-panel-num" decimals="2" />
                  </div>
                  <div class="card-panel-text"  style="font-size:14px;">
                      下单扣款：
                      ￥<count-to :start-val="0" :end-val="platAmount.receiveFineFee" :duration="1000" decimals="2" class="card-panel-num" style="font-size:14px;"/>
                      <span style="margin-left:10px;"></span>
                      接单罚款：
                      ￥<count-to :start-val="0" :end-val="platAmount.userFineFee" :duration="1000" decimals="2" class="card-panel-num" style="font-size:14px;" /> 
                  </div>
                </div>
            </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel">
                <div class="card-panel-description">
                  <div class="card-panel-text" style="color: #333333;">
                      提现：￥ <count-to :start-val="0" :end-val="platAmount.cashoutFee" :duration="1000" decimals="2" class="card-panel-num"  /> 
                  </div>
                  <div class="card-panel-text" style="font-size:14px;">
                      个人提现：￥<count-to :start-val="0" :end-val="platAmount.cashoutPersonFee" :duration="1000" decimals="2" class="card-panel-num" style="font-size:14px;" /> 
                      <span style="margin-left:10px;"></span>
                      公司提现：￥<count-to :start-val="0" :end-val="platAmount.cashoutCompanyFee" :duration="1000" decimals="2" class="card-panel-num" style="font-size:14px;" /> 
                  </div>          
                </div>
            </div>
            </el-col>
        </el-row>

       
            <el-row :gutter="10" style="background: #fff; ">
            <el-col :span="10">
               <el-card class="box-card">
                <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
                   
                    <el-form-item label="选择时间">
                        <el-date-picker
                            v-model="daterangeCreateTime"
                            size="small"
                            style="width: 240px"
                            value-format="yyyy-MM-dd"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    </el-form-item>
                    </el-form>

                   <el-tabs  v-model="tabActiveName" @tab-click="handleTabClick">
                        <el-tab-pane label="全部" name="all"></el-tab-pane>
                        <el-tab-pane  v-for="dict in typeOptions" :key="dict.dictValue" :label="dict.dictLabel" :name="dict.dictValue"></el-tab-pane>
                    </el-tabs>

                    <el-table v-loading="loading" :data="feeList" show-summary >
                        <el-table-column label="类型" align="center" prop="type" :formatter="typeFormat" width="120"/>
                        <el-table-column label="内容" align="left" prop="content" show-overflow-tooltip />
                        <el-table-column label="金额" align="center" prop="fee" width="100"/>
                        <el-table-column label="创建时间" align="center" prop="createTime" width="150">
                            <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.createTime) }}</span>
                            </template>
                        </el-table-column>
                    </el-table>
                    
                    <pagination
                        v-show="total>0"
                        :total="total"
                        layout="total,sizes,prev, pager, next"
                        :page.sync="queryParams.pageNum"
                        :limit.sync="queryParams.pageSize"
                        @pagination="getList"
                    />
                </el-card>
            </el-col>
            <el-col :span="14">
               <el-card class="box-card">
                <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
                      
                    <el-form-item label="评论时间">
                        <el-date-picker
                            v-model="daterangeOrderTime"
                            size="small"
                            style="width: 240px"
                            value-format="yyyy-MM-dd"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleOrderQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetOrderQuery">重置</el-button>
                    </el-form-item>
                    </el-form>

                    <el-tabs  >
                        <el-tab-pane label="订单列表" ></el-tab-pane>
                    </el-tabs>
                    <el-table v-loading="cloading" :data="orderList" show-summary >      
                      <el-table-column label="订单编号" align="left" width="170" prop="num" />
                      <el-table-column label="订单信息" align="left" prop="attribute" show-overflow-tooltip />
                      <!-- <el-table-column label="下单人" align="left" prop="username" width="120" >
                        <template slot-scope="scope">
                          <div>{{scope.row.username}}</div>
                          <div>{{scope.row.telephone}}</div>
                        </template>
                      </el-table-column>
                      <el-table-column label="接单人" align="left" prop="receiveName" width="120" >
                        <template slot-scope="scope">
                          <div>{{scope.row.receiveName}}</div>
                          <div>{{scope.row.receivePhone}}</div>
                        </template>
                      </el-table-column> -->
                      <el-table-column label="应付金额" align="center" prop="payable" />
                      <el-table-column label="实付金额" align="center" prop="pay" />
                      <el-table-column label="优惠金额" align="center" prop="pay" >
                        <template slot-scope="scope">
                          {{scope.row.payable - scope.row.pay}}
                        </template>
                      </el-table-column> 
                      <el-table-column label="下单时间" align="center" prop="publishTime" width="150">
                          <template slot-scope="scope">
                              <span>{{ parseTime(scope.row.publishTime) }}</span>
                          </template>
                      </el-table-column>
                      <el-table-column label="评论时间" align="center" prop="commentTime" width="150">
                          <template slot-scope="scope">
                              <span>{{ parseTime(scope.row.commentTime) }}</span>
                          </template>
                      </el-table-column>
                    </el-table>
                    
                    <pagination
                      v-show="ordertotal>0"
                      :total="ordertotal"
                      :page.sync="queryOrderParams.pageNum"
                      :limit.sync="queryOrderParams.pageSize"
                      @pagination="getOrderList"
                    />
                    </el-card>
            </el-col>
            
        </el-row>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import { listFee} from "@/api/user/fee";
import { getListOrder } from "@/api/business/order";
import { getPlatformAmount } from "@/api/report/platform";

export default {
  components: {
    CountTo
  },
  data() { 
    return {
      platAmount: {},
      roles: null,
      tabActiveName: 'all',
      // 遮罩层
      loading: true,
      cloading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      ordertotal: 0,
      // 收入支出明细表格数据
      feeList: [],
      typeOptions: [],
      daterangeCreateTime: [],
      daterangeOrderTime: [],
      couponUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        userName: null,
        type: null,
        content: null,
        fee: null,
        params:{}
      },
      // 查询参数
      queryOrderParams: {
        pageNum: 1,
        pageSize: 10,
        params:{}
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getDicts("user_fee_type").then(response => {
      this.typeOptions = response.data;
    });
    this.getList();
    this.getOrderList();
    this.getAmount();
  },
  methods: {
    handleQuery(){
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.handleQuery();
    },
    /** 重置按钮操作 */
    resetOrderQuery() {
      this.daterangeOrderTime = [];
      this.handleOrderQuery();
    },
    handleOrderQuery(){
      this.getOrderList();
    },
    handleTabClick(tab, event){
      if (tab.name != 'all') {
        this.queryParams.type = tab.name;
      }else{
        this.queryParams.type = '';
      }
      this.getList();
    },
    // 字典状态字典翻译
    typeFormat(row, column) {
      
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    getAmount() {
      getPlatformAmount().then(res => {
        console.log(res)
        this.platAmount = res.data;
      });
    },
    /** 查询收入支出明细列表 */
    getList() {
      this.loading = true;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      } else {
        this.queryParams.params = {};
      }
      this.queryParams.userId = 1;
      listFee(this.queryParams).then(response => {
        this.feeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询订单管理列表 */
    getOrderList() {
      this.cloading = true;
      this.queryOrderParams.params = {};
      this.queryOrderParams.status = 25;
      if (null != this.daterangeOrderTime && '' != this.daterangeOrderTime) {
        this.queryOrderParams.params["beginCommentTime"] = this.daterangeOrderTime[0];
        this.queryOrderParams.params["endCommentTime"] = this.daterangeOrderTime[1];
      } else {
        this.queryOrderParams.params = {};
      }
      // if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
      //   this.queryOrderParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
      //   this.queryOrderParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      // }
      getListOrder(this.queryOrderParams).then(response => {
        this.orderList = response.rows;
        this.ordertotal = response.total;
        this.cloading = false;
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 0px;

  .card-panel-col {
    margin-bottom: 10px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      // padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 90px;
    }

    .card-panel-description {
      // float: right;
      font-weight: bold;
      margin: 20px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

</style>
